package com.chushouya.order.service.admin;



import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;

import com.general.framework.core.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AlipayNotifyTypeService {

//    @Resource
//    private AlipayUserAgreementService alipayUserAgreementService;

    private Map<String, Consumer<Map>> grantTypeMap = new HashMap<>();

    /**
     * 初始化订单逻辑,代替了if-else部分
     * key: 订单操作类型
     * value: lambda表达式,操作订单
     */
    @PostConstruct
    public void dispatcherInit() {

        //用户签约成功通知类型
//        grantTypeMap.put(AlipayNotifyMethodEnum.DUT_USER_SIGN.value(), data -> alipayUserAgreementService.alipayUserAgreementSign(data));

        //用户解约成功通知类型
//        grantTypeMap.put(AlipayNotifyMethodEnum.DUT_USER_UNSIGN.value(), data -> alipayUserAgreementService.alipayUserAgreementUnsign(data));




    }

    public void getResult(Map<String, String> params) {
        try {
            Consumer<Map> result = grantTypeMap.get(params.get("notify_type"));
            if (Objects.isNull(result)) {
                log.info("网关操作不存在 {}", params.get("notify_type"));
                return;
            }
            result.accept(params);
        } catch (BaseException e) {
            log.info("网关操作失败：{}", e.getMessage());
        } catch (Exception e) {
            log.error("网关操作失败：{}", e.getMessage());
        }

    }
}
